from PySide6.QtWidgets import QPlainTextEdit
from PySide6.QtCore import Signal,QDateTime

class PlainTextEdit(QPlainTextEdit):
    """纯文本编辑

    :param QPlainTextEdit: PySide6 QPlainTextEdit
    """
    hasText = Signal(bool)

    def __init__(self):
        """初始化
        """
        super().__init__()
        # 基于文本改变 检测是否有内容
        self.textChanged.connect(self.__has_text)
    
    def __has_text(self) -> bool:
        """判断是否有文本
        """
        self.hasText.emit(True) if self.toPlainText() else self.hasText.emit(False)

    def get_selected_text(self) -> str:
        """获取选中的文本
        """
        return self.textCursor().selectedText()

    def insert_date_time(self):
        """插入日期时间
        """
        currentDateTime = QDateTime.currentDateTime()
        formattedTime = currentDateTime.toString("hh:mm yyyy/MM/dd")
        self.insertPlainText(formattedTime)




